package com.credit.mola.app.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.credit.mola.lib_baseadapter.SikadwaRecyclerViewAdapter
import com.credit.mola.lib_baseadapter.SikadwaViewHolderHelper
import com.credit.mola.app.R
import org.json.JSONObject

/**
 * Sikadwa
 * @Author wwdeng
 * @CreateTime: 2024/4/23 17:24
 * @Annotation：权限类型适配器
 */
class PermissionListAdapter(recyclerView: RecyclerView?) : SikadwaRecyclerViewAdapter<JSONObject>(recyclerView,R.layout.item_permission_list) {

    override fun setItemChildListener(helper: SikadwaViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.btnGoToAgree)
    }

    override fun fillData(helper: SikadwaViewHolderHelper, position: Int, model: JSONObject) {
        val imgPermissionIcon = helper.getImageView(R.id.imgPermissionIcon)
        imgPermissionIcon.setImageResource(model.optInt("icon"))
        val textPermissionTitle = helper.getTextView(R.id.textPermissionTitle)
        textPermissionTitle.text = model.optString("title")

        helper.setText(R.id.textAgreeAmount," + ${model.optString("loanAmount")}")
        helper.setText(R.id.textPassRate," + ${model.optString("passRate")}"+"%")

        val imgPermissionStatus = helper.getImageView(R.id.imgPermissionStatus)
        when(model.optInt("isAgree")){
            1 -> {
                imgPermissionStatus.setImageResource(R.mipmap.img_credit_limit_select)
                helper.setVisibility(R.id.loanAmountLayout,View.GONE)
                helper.setVisibility(R.id.passRateLayout,View.GONE)
                helper.setVisibility(R.id.btnGoToAgree,View.GONE)
                helper.setVisibility(R.id.textAgreed,View.VISIBLE)
            }
            0 -> {
                imgPermissionStatus.setImageResource(R.mipmap.img_credit_limit_normal)
                helper.setVisibility(R.id.loanAmountLayout,View.VISIBLE)
                helper.setVisibility(R.id.passRateLayout,View.VISIBLE)
                helper.setVisibility(R.id.btnGoToAgree,View.VISIBLE)
                helper.setVisibility(R.id.textAgreed,View.GONE)
            }
            else -> {
                imgPermissionStatus.setImageResource(R.mipmap.img_permission_item_rejected_icon)
                helper.setVisibility(R.id.loanAmountLayout,View.VISIBLE)
                helper.setVisibility(R.id.passRateLayout,View.VISIBLE)
                helper.setVisibility(R.id.btnGoToAgree,View.VISIBLE)
                helper.setVisibility(R.id.textAgreed,View.GONE)
            }
        }

        when (position) {
            0 -> {
                helper.setVisibility(R.id.vLineTop, View.INVISIBLE)
                helper.setVisibility(R.id.vLineBottom, View.VISIBLE)
            }
            itemCount - 1 -> {
                helper.setVisibility(R.id.vLineTop, View.VISIBLE)
                helper.setVisibility(R.id.vLineBottom, View.INVISIBLE)
            }
            else -> {
                helper.setVisibility(R.id.vLineTop, View.VISIBLE)
                helper.setVisibility(R.id.vLineBottom, View.VISIBLE)
            }
        }
    }
}